<div id="content-header">
    <?php
    $this->widget('bootstrap.widgets.TbBreadcrumbs', array(
        'links' => array('Tin tức' => 'index', 'Danh mục'),
        'htmlOptions' => array('id' => 'breadcrumb')
    ));
    ?>
</div>
<?php
$form = $this->beginWidget('CActiveForm', array(
    'enableAjaxValidation' => TRUE,
        ));
?>

<div class="btn-group btn-group-admin">
    <?php
    echo Chtml::link('Thêm mới', array('create'), array('class' => 'btn btn-primary'));
    echo CHtml::ajaxSubmitButton('Xóa ', array('product/deleteAll'), array('success' => 'reloadGrid', 'beforeSend' => 'function(){
            return confirm("Bạn có chắc chắn muốn xóa những mục được chọn?")
        }'), array('class' => 'btn btn-primary btn-sub'));
    ?>
</div>

<div class="row-fluid">
    <div class="span12">
        <div class="widget-box">
            <div class="widget-content nopadding">
                <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper" role="grid">
                    <?php
                    $this->widget('bootstrap.widgets.TbGridView', array(
                        'id' => 'table-grid',
                        'dataProvider' => $model->search(),
                        'filter' => $model,
                        'selectableRows' => 2,
                        'columns' => array(
                            array(
                                'header' => '#',
                                'class' => 'ext.CounterColumn',
                                'htmlOptions' => array('class' => 'tdheader')
                            ),
                            array(
                                'id' => 'autoId',
                                'class' => 'zii.widgets.grid.CCheckBoxColumn',
                                'selectableRows' => '50',
                            ),
                             array(
                                'name' => 'Danh mục',
                                'value' => '$data->category->name',
                                'type' => 'raw',
                                'filter' => FALSE,
                            ),
                            array(
                                'name' => 'file',
                                'value' => '$data->file',
                                'type' => 'raw',
                                'filter' => FALSE,
                            ),
                            array(
                                'name' => 'name',
                                'type' => 'raw',
                                'value' => '$data->name',
                                'filter' => FALSE,
                            ),
                            array(
                                'name' => 'create_time',
                                'type' => 'raw',
                                'value' => 'date("d-m-Y",$data->create_time)',
                                'filter' => FALSE,
                            ),
                            array(
                                'name' => 'status',
                                'type' => 'raw',
                                'value' => '"<div id=".$data->id.">".CHtml::link(($data->status==1)?"Kích hoạt":"Chưa kích hoạt",
                                        CHtml::normalizeUrl("javascript:void(0)"),
                                       
                                        array(
                                            "rel" => $data->id,
                                             "onclick"=>"status(".$data->id.",".$data->status.")",
                                        )
                                    )."</div>"',
                                'filter' => array(1 => 'Kích hoạt', 0 => 'Chưa kích hoạt'),
                                'htmlOptions' => array('class' => 'tdstatus')
                            ),
                            array(
                                'class' => 'CButtonColumn',
                                'template' => '{update}{delete}',
                            )
                        ),
                    ));
                    $cs = Yii::app()->getClientScript();
                    $cs->registerScript('reloadgrid', 'function reloadGrid(data){$.fn.yiiGridView.update("table-grid")}', CClientScript::POS_END);
                    ?>
                </div>
            </div>

        </div>
    </div>
</div>
<?php $this->endWidget(); ?>

<script>
    function status(id, status) {
        $.ajax({
            type: 'POST',
            url: 'status',
            data: {
                'id': id,
                'status': status
            },
            success: function(data) {
                $.fn.yiiGridView.update('table-grid');
            }
        });

    }

</script>